home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / IEEE / src / bench / whetstone.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-27  |  14.4 KB  |  668 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *      Whetstone benchmark in C.  This program is a translation of the   *
  4.  *      original Algol version in "A Synthetic Benchmark" by H.J. Curnow  *
  5.  *      and B.A. Wichman in Computer Journal, Vol  19 #1, February 1976.  *
  6.  *                                                                        *
  7.  *      Used to test compiler efficiency, optimization, and double        *
  8.  *      precision floating-point performance.  This version is specific   *
  9.  *      to the Turbo-Amiga and Amiga but it can be easily adapted to      *
  10.  *      other systems by replacing the timeticks() routine with your own. *
  11.  *                                                                        *
  12.  **************************************************************************/
  13.  
  14. #define ITERATIONS   10       /* 1 Million Whetstone instructions    */
  15.  
  16. /* #define POUT  */           /* Leave as is for 'Official' result.  */
  17.  
  18. /* #define MTEST */           /* define for Module timing results    */
  19.                               /* only.  Leave as is for 'Official'   */
  20.                               /* result.                             */
  21.  
  22.                               /* These includes are specific to my   */
  23.                               /* Turbo-Amiga/Amiga system.  Replace  */
  24.                               /* with your own set.                  */
  25.  
  26. #include <stdio.h>
  27. #include <math.h>
  28. double atan(),acos(),asin(),tan(),cos(),sin();
  29. double log(),exp(),sqrt();
  30.  
  31. double   e1[4],e2[4];
  32. double   t, t1, t2, x, y, z, x1, x2, x3, x4;
  33. long     i, j, k, l;
  34. long     n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11;
  35. long     m, m1, m2, loops, KWhets;
  36.  
  37. long  starttime, stoptime, nulltime;
  38. long  sumtime, benchtime,timeticks();     /* Replace timeticks() with */
  39.                                           /* your own system timing   */
  40.                                           /* routine.                 */
  41.  
  42. main()
  43. {
  44.    printf("\n   Whetstone C Benchmark V1.0\n");
  45.  
  46.    starttime = timeticks();               /* Calculate timer call delay */
  47.    stoptime  = timeticks();
  48.    nulltime  = stoptime - starttime;
  49.  
  50.    /************************/
  51.    /* initialize constants */
  52.    /************************/
  53.  
  54.    t   =   0.499975;
  55.    t1  =   0.500250;
  56.    t2  =   2.0;
  57.  
  58.    /***********************/
  59.    /* Set Module Weights. */
  60.    /***********************/
  61.  
  62.    m = 10;                    /* m = 10 is used to obtain better timing  */
  63.    loops = m * ITERATIONS;    /* accuracy only.  Slow systems should use */
  64.    n1  =   0 * loops;         /* m = 1.                                  */
  65.    n2  =  12 * loops;
  66.    n3  =  14 * loops;
  67.    n4  = 345 * loops;
  68.    n5  =   0 * loops;
  69.    n6  = 210 * loops;
  70.    n7  =  32 * loops;
  71.    n8  = 899 * loops;
  72.    n9  = 616 * loops;
  73.    n10 =   0 * loops;
  74.    n11 =  93 * loops;
  75.  
  76.  
  77.                               /* Start Timing the Whetstone here. */
  78.    starttime = timeticks();
  79.  
  80.    /*********************************/
  81.    /* MODULE 1:  simple identifiers */
  82.    /*********************************/
  83.  
  84.    x1 =  1.0;
  85.    x2 = -1.0;
  86.    x3 = -1.0;
  87.    x4 = -1.0;
  88.  
  89.    if( n1 > 0 )
  90.    {
  91.      for(i = 1; i <= n1; i++)
  92.      {
  93.       x1 = ( x1 + x2 + x3 - x4 ) * t;
  94.       x2 = ( x1 + x2 - x3 - x4 ) * t;
  95.       x3 = ( x1 - x2 + x3 + x4 ) * t;
  96.       x4 = (-x1 + x2 + x3 + x4 ) * t;
  97.      }
  98.    }
  99.  
  100. #ifdef MTEST                                    /* Module 1 Run Time */
  101.    stoptime  = timeticks();
  102.    benchtime = stoptime - starttime - nulltime;
  103.    m = 1;
  104.    x = (double)benchtime/50.0;
  105.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  106. #endif
  107.  
  108. #ifdef POUT
  109.    Pout(n1, n1, n1, x1, x2, x3, x4);
  110. #endif
  111.  
  112.    /*****************************/
  113.    /* MODULE 2:  Array Elements */
  114.    /*****************************/
  115. #ifdef MTEST
  116.    starttime = timeticks();
  117. #endif
  118.  
  119.    e1[0] =  1.0;        /* Start at element 0 in C, vice 1 in Fortran */
  120.    e1[1] = -1.0;
  121.    e1[2] = -1.0;
  122.    e1[3] = -1.0;
  123.  
  124.    if( n2 > 0 )
  125.    {
  126.      for (i = 1; i <= n2; i++)
  127.      {
  128.       e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  129.       e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  130.       e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  131.       e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  132.      }
  133.    }
  134.  
  135. #ifdef MTEST
  136.    stoptime  = timeticks();
  137.    benchtime = stoptime - starttime - nulltime;
  138.    sumtime   = benchtime;
  139.    m = 2;
  140.    x = (double)benchtime/50.0;
  141.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  142. #endif
  143.  
  144. #ifdef POUT
  145.    Pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  146. #endif
  147.  
  148.    /*********************************/
  149.    /* MODULE 3:  Array as Parameter */
  150.    /*********************************/
  151. #ifdef MTEST
  152.    starttime = timeticks();
  153. #endif
  154.  
  155.    if( n3 > 0 )
  156.    {
  157.      for (i = 1; i <= n3; i++)
  158.      {
  159.       pa(e1);
  160.      }
  161.    }
  162.  
  163. #ifdef MTEST
  164.    stoptime  = timeticks();
  165.    benchtime = stoptime - starttime - nulltime;
  166.    m1 = benchtime;
  167.    m = 3;
  168.    x = (double)benchtime/50.0;
  169.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  170. #endif
  171.  
  172. #ifdef POUT
  173.    Pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  174. #endif
  175.  
  176.    /********************************/
  177.    /* MODULE 4:  Conditional Jumps */
  178.    /********************************/
  179. #ifdef MTEST
  180.    starttime = timeticks();
  181. #endif
  182.  
  183.    j = 1;
  184.  
  185.    if( n4 > 0 )
  186.    {
  187.      for (i = 1; i <= n4; i++)
  188.      {
  189.       if (j == 1)
  190.          j = 2;
  191.       else
  192.          j = 3;
  193.  
  194.       if (j > 2)
  195.          j = 0;
  196.       else
  197.          j = 1;
  198.  
  199.       if (j < 1 )
  200.          j = 1;
  201.       else
  202.          j = 0;
  203.      }
  204.    }
  205.  
  206. #ifdef MTEST
  207.    stoptime  = timeticks();
  208.    benchtime = stoptime - starttime - nulltime;
  209.    sumtime   = sumtime + benchtime;
  210.    m = 4;
  211.    x = (double)benchtime/50.0;
  212.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  213.    starttime = timeticks();
  214. #endif
  215.  
  216. #ifdef POUT
  217.    Pout(n4, j, j, x1, x2, x3, x4);
  218. #endif
  219.  
  220.    /**********************/
  221.    /* MODULE 5:  Omitted */
  222.    /**********************/
  223.  
  224.  
  225. #ifdef MTEST
  226.    benchtime = 0;
  227.    m = 5;
  228.    x = 0.0;
  229.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  230. #endif
  231.  
  232. #ifdef POUT
  233.    Pout(n4, j, j, x1, x2, x3, x4);
  234. #endif
  235.  
  236.    /*********************************/
  237.    /* MODULE 6:  Integer Arithmetic */
  238.    /*********************************/
  239. #ifdef MTEST
  240.    starttime = timeticks();
  241. #endif
  242.  
  243.    j = 1;
  244.    k = 2;
  245.    l = 3;
  246.  
  247.    if( n6 > 0 )
  248.    {
  249.      for (i = 1; i <= n6; i++)
  250.      {
  251.       j = j * (k - j) * (l -k);
  252.       k = l * k - (l - j) * k;
  253.       l = (l - k) * (k + j);
  254.  
  255.       e1[l - 2] = j + k + l;          /* Remember we started at e1[0]. */
  256.       e1[k - 2] = j * k * l;          /* l-2 in C, vice l-1 in Fortran */
  257.      }
  258.    }
  259.  
  260. #ifdef MTEST
  261.    stoptime  = timeticks();
  262.    benchtime = stoptime - starttime - nulltime;
  263.    sumtime   = sumtime + benchtime;
  264.    m = 6;
  265.    x = (double)benchtime/50.0;
  266.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  267. #endif
  268.  
  269. #ifdef POUT
  270.    Pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  271. #endif
  272.  
  273.    /**************************************/
  274.    /* MODULE 7:  Trigonometric Functions */
  275.    /**************************************/
  276. #ifdef MTEST
  277.    starttime = timeticks();
  278. #endif
  279.  
  280.    x = 0.5;
  281.    y = 0.5;
  282.  
  283.    if( n7 > 0 )
  284.    {
  285.      for(i = 1; i <= n7; i++)
  286.      {
  287.       x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  288.       y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  289.      }
  290.    }
  291.  
  292. #ifdef MTEST
  293.    stoptime  = timeticks();
  294.    benchtime = stoptime - starttime - nulltime;
  295.    sumtime   = sumtime + benchtime;
  296.    m = 7;
  297.    x1 = (double)benchtime/50.0;
  298.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  299. #endif
  300.  
  301. #ifdef POUT
  302.    Pout(n7, j, k, x, x, y, y);
  303. #endif
  304.  
  305.    /******************************/
  306.    /* MODULE 8:  Procedure Calls */
  307.    /******************************/
  308. #ifdef MTEST
  309.    starttime = timeticks();
  310. #endif
  311.  
  312.    x = 1.0;
  313.    y = 1.0;
  314.    z = 1.0;
  315.  
  316.    if( n8 > 0 )
  317.    {
  318.      for (i = 1; i <= n8; i++)
  319.      {
  320.       p3(x, y, &z);
  321.      }
  322.    }
  323.  
  324. #ifdef MTEST
  325.    stoptime  = timeticks();
  326.    benchtime = stoptime - starttime - nulltime;
  327.    m1 = m1 + benchtime;
  328.    m = 8;
  329.    x1 = (double)benchtime/50.0;
  330.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  331. #endif
  332.  
  333. #ifdef POUT
  334.    Pout(n8, j, k, x, y, z, z);
  335. #endif
  336.  
  337.    /*******************************/
  338.    /* MODULE 9:  Array References */
  339.    /*******************************/
  340. #ifdef MTEST
  341.    starttime = timeticks();
  342. #endif
  343.  
  344.    j = 1;
  345.    k = 2;
  346.    l = 3;
  347.  
  348.    e1[0] = 1.0;
  349.    e1[1] = 2.0;
  350.    e1[2] = 3.0;
  351.  
  352.    if( n9 > 0 )
  353.    {
  354.      for(i = 1; i <= n9; i++)
  355.      {
  356.       p0();
  357.      }
  358.    }
  359.  
  360. #ifdef MTEST
  361.    stoptime  = timeticks();
  362.    benchtime = stoptime - starttime - nulltime;
  363.    m1 = m1 + benchtime;
  364.    m = 9;
  365.    x = (double)benchtime/50.0;
  366.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  367. #endif
  368.  
  369. #ifdef POUT
  370.    Pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  371. #endif
  372.  
  373.    /**********************************/
  374.    /* MODULE 10:  Integer Arithmetic */
  375.    /**********************************/
  376. #ifdef MTEST
  377.    starttime = timeticks();
  378. #endif
  379.  
  380.    j = 2;
  381.    k = 3;
  382.  
  383.    if( n10 > 0 )
  384.    {
  385.      for(i = 1; i <= n10; i++)
  386.      {
  387.       j = j + k;
  388.       k = j + k;
  389.       j = k - j;
  390.       k = k - j - j;
  391.      }
  392.    }
  393.  
  394. #ifdef MTEST
  395.    stoptime  = timeticks();
  396.    benchtime = 0;
  397.    m = 10;
  398.    x = 0.0;
  399.    printf("   End Module %ld.  Benchtime(sec) = %lf\n",m,x);
  400. #endif
  401.  
  402. #ifdef POUT
  403.    Pout(n10, j, k, x1, x2, x3, x4);
  404. #endif
  405.  
  406.    /**********************************/
  407.    /* MODULE 11:  Standard Functions */
  408.    /**********************************/
  409. #ifdef MTEST
  410.    starttime = timeticks();
  411. #endif
  412.  
  413.    x = 0.75;
  414.  
  415.    if( n11 > 0 )
  416.    {
  417.      for(i = 1; i <= n11; i++)
  418.      {
  419.       x = sqrt( exp( log(x) / t1) );
  420.      }
  421.    }
  422.  
  423. #ifdef MTEST
  424.    stoptime  = timeticks();
  425.    benchtime = stoptime - starttime - nulltime;
  426.    sumtime   = sumtime + benchtime;
  427.    m = 11;
  428.    x1 = (double)benchtime/50.0;
  429.    printf("   End Module %ld.  Benchtime(sec) = %lf\n\n",m,x1);
  430. #endif
  431.  
  432. #ifdef POUT
  433.    Pout(n11, j, k, x, x, x, x);
  434. #endif
  435.  
  436.    /********************************************************/
  437.    /* MODULE 12:  Array as a Parameter.                    */
  438.    /* Same as Module 3 except Subroutine overhead removed. */
  439.    /********************************************************/
  440.  
  441. #ifdef MTEST
  442.  
  443.    starttime = timeticks();
  444.    if( n3 > 0 )
  445.    {
  446.      for (i = 1; i <= n3; i++)
  447.      {
  448.       j = 0;
  449.         lab:
  450.       e2[0] = (  e2[0] + e2[1] + e2[2] - e2[3] ) * t;
  451.       e2[1] = (  e2[0] + e2[1] - e2[2] + e2[3] ) * t;
  452.       e2[2] = (  e2[0] - e2[1] + e2[2] + e2[3] ) * t;
  453.       e2[3] = ( -e2[0] + e2[1] + e2[2] + e2[3] ) /t2;
  454.       j++;
  455.  
  456.       if (j < 6)
  457.          goto lab;
  458.      }
  459.    }
  460.  
  461.    stoptime  = timeticks();
  462.    benchtime = stoptime - starttime - nulltime;
  463.    m2   = benchtime;
  464.    m = 3;
  465.    x1 = (double)benchtime/50.0;
  466.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  467.  
  468. #endif
  469.  
  470. #ifdef POUT
  471.    Pout(n11, j, k, x, x, x, x);
  472. #endif
  473.  
  474.    /********************************************************/
  475.    /* MODULE 13:  Array as a Parameter.                    */
  476.    /* Same as Module 8 except Subroutine overhead removed. */
  477.    /********************************************************/
  478.  
  479. #ifdef MTEST
  480.  
  481.    starttime = timeticks();
  482.    x = 1.0;
  483.    y = 1.0;
  484.    z = 1.0;
  485.  
  486.    if( n8 > 0 )
  487.    {
  488.      for (i = 1; i <= n8; i++)
  489.      {
  490.       x = t * (x + y);
  491.       y = t * (x + y);
  492.       z = (x + y) /t2;
  493.      }
  494.    }
  495.  
  496.    stoptime  = timeticks();
  497.    benchtime = stoptime - starttime - nulltime;
  498.    m2   = m2 + benchtime;
  499.    m = 8;
  500.    x1 = (double)benchtime/50.0;
  501.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  502.  
  503. #endif
  504.  
  505. #ifdef POUT
  506.    Pout(n11, j, k, x, x, x, x);
  507. #endif
  508.  
  509.    /********************************************************/
  510.    /* MODULE 14:  Array as a Parameter.                    */
  511.    /* Same as Module 9 except Subroutine overhead removed. */
  512.    /********************************************************/
  513.  
  514. #ifdef MTEST
  515.  
  516.    starttime = timeticks();
  517.    j = 1;
  518.    k = 2;
  519.    l = 3;
  520.  
  521.    e1[0] = 1.0;
  522.    e1[1] = 2.0;
  523.    e1[2] = 3.0;
  524.  
  525.    if( n9 > 0 )
  526.    {
  527.      for(i = 1; i <= n9; i++)
  528.      {
  529.       e1[j] = e1[k];
  530.       e1[k] = e1[l];
  531.       e1[l] = e1[j];
  532.      }
  533.    }
  534.  
  535.    stoptime  = timeticks();
  536.    benchtime = stoptime - starttime - nulltime;
  537.    m2 = m2 + benchtime;
  538.    m = 9;
  539.    x1 = (double)benchtime/50.0;
  540.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  541.  
  542. #endif
  543.  
  544. #ifdef POUT
  545.    Pout(n11, j, k, x, x, x, x);
  546. #endif
  547.  
  548.    /**************************/
  549.    /* End of Whetstone Tests */
  550.    /**************************/
  551.  
  552. #ifdef MTEST
  553.    m1 = m1 + sumtime;
  554.    m2 = m2 + sumtime;
  555.    x1 = (double)m1/50.0;
  556.    x2 = (double)m2/50.0;
  557.  
  558.    printf("Standard Whetstone Result\n");
  559.    printf("   Benchtime(sec) = %lf\n",x1);
  560.    x  = 100.0 * (double)loops / x1;
  561.    KWhets = (long)x;
  562.    printf("   KWhets/sec     = %ld\n",KWhets);
  563.  
  564.    printf("Result with subroutine call replaced with subroutine code\n");
  565.    printf("   Benchtime(sec) = %lf\n",x2);
  566.    x  = 100.0 * (double)loops / x2;
  567.    KWhets = (long)x;
  568.    printf("   KWhets/sec     = %ld\n",KWhets);
  569.  
  570. #else
  571.  
  572.    stoptime  = timeticks();
  573.    benchtime = stoptime - starttime - nulltime;
  574.    x1 = (double)benchtime/50.0;
  575.    printf("   Benchtime(sec) = %lf\n",x1);
  576.    x2 = 100.0 * (double)loops / x1;
  577.    KWhets = (long)x2;
  578.    printf("   KWhets/sec     = %ld\n\n",KWhets);
  579.  
  580. #endif
  581.  
  582.    exit(0);
  583.  
  584. }
  585.  
  586. /*******************/
  587. /* Subroutine pa() */
  588. /*******************/
  589.  
  590. pa(e)                /* Exactly as in the Algol 60 version, but we */
  591.                      /* could do away with that 'goto'.            */
  592. double e[4];
  593.  
  594. {
  595.    int j;
  596.  
  597.    j = 0;
  598.      lab:
  599.    e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  600.    e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  601.    e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  602.    e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  603.    j ++;
  604.  
  605.    if (j < 6)
  606.       goto lab;
  607. }
  608.  
  609. /************************/
  610. /* Subroutine p3(x,y,z) */
  611. /************************/
  612.  
  613. p3(x, y, z)
  614.  
  615. double x, y, *z;
  616.  
  617. {
  618.    x  = t * (x + y);
  619.    y  = t * (x + y);
  620.    *z = (x + y) /t2;
  621. }
  622.  
  623. /*******************/
  624. /* Subroutine p0() */
  625. /*******************/
  626.  
  627. p0()
  628. {
  629.    e1[j] = e1[k];
  630.    e1[k] = e1[l];
  631.    e1[l] = e1[j];
  632. }
  633.  
  634. /*********************/
  635. /* Subroutine Pout() */
  636. /*********************/
  637.  
  638. #ifdef POUT
  639. Pout(n, j, k, x1, x2, x3, x4)
  640.  
  641. long  n, j, k;
  642. double x1, x2, x3, x4;
  643.  
  644. {
  645.    printf("%5ld %5ld %5ld   %11.3le %11.3le %11.3le %11.3le\n",
  646.       n, j, k, x1, x2, x3, x4);
  647. }
  648. #endif
  649.  
  650. /*************************************/
  651. /* Amiga Time Ticks ( 50 * seconds ) */
  652. /*************************************/
  653.  
  654. long timeticks()
  655. {
  656.       struct   tt {
  657.          long  days;
  658.          long  minutes;
  659.          long  ticks;
  660.       } tt;
  661.       DateStamp(&tt);
  662.   return (tt.ticks + (tt.minutes * 60L * 50L ));
  663. }
  664.  
  665. /*--------------------- End Of Whetstone C Source Code -----------------*/
  666.  
  667.  
  668.